<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>管理空间</title>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/lhgcalendar/lhgcore.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/js/lhgcalendar/lhgcalendar.js"></script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="My Play Responsive web template, Bootstrap Web Templates, Flat Web Templates, Andriod Compatible web template, 
Smartphone Compatible web template, free webdesigns for Nokia, Samsung, LG, SonyErricsson, Motorola web design" />
<script type="application/x-javascript">addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } 
</script>
<!-- bootstrap -->
<link href="${pageContext.request.contextPath}/css/bootstrap.min.css" rel='stylesheet' type='text/css' media="all" />
<!-- //bootstrap -->
<link href="${pageContext.request.contextPath}/css/dashboard.css" rel="stylesheet">
<!-- Custom Theme files -->
<link href="${pageContext.request.contextPath}/css/style.css" rel='stylesheet' type='text/css' media="all" />
<script src="${pageContext.request.contextPath}/js/jquery-1.11.1.min.js"></script>
<link href="${pageContext.request.contextPath}/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />
<link href="${pageContext.request.contextPath}/css/font-awesome.min.css" media="all" rel="stylesheet" type="text/css" />
<script src="${pageContext.request.contextPath}/js/fileinput.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/videoplayer/flowplayer-3.2.8.min.js"  type="text/javascript"></script>  
<script src="${pageContext.request.contextPath}/js/layer/layer.js" type="text/javascript"></script>
<!--start-smoth-scrolling-->
<!-- fonts -->
</head>
<body>
	<jsp:include page="header.jsp"></jsp:include>

	<!-- upload -->
	<div class="upload">
		<!-- container -->
		<div class="container">
			<!-- 报表编辑页面内容 -->
			<div class="row clearfix report-content">
				<div class="col-md-2 column report-left">
					<div class="form-group text-center report-left-cell">
						<div class="glyphicon glyphicon-wrench">&nbsp;视频审核</div>
					</div>
					<div class="form-group text-center report-left-cell">
						<div class="glyphicon glyphicon-globe">&nbsp;留言审核</div>
					</div>
				</div>
				<div class="col-md-10 column video-grid">
					<div class="user-container">
						<div class="account-message user-item ">
							<form action="${pageContext.request.contextPath}/users/update?username=${username }" method="post" id="updateid">
									<div class="account-message-header">
										<h3>视频审核</h3>
										<hr />
									</div>
									<div class="account-message-content">
										<div class="column">
										<table class="table table-hover">
											  <thead>
											    <tr>
											      <th>编号</th>
											      <th>缩略图</th>
											      <th>名称</th>
											      <th>上传用户</th>
											      <th>上传时间</th>
											      <th>持续时间</th>
											      <th>状态</th>
											    </tr>
											  </thead>
											  <tbody>
												  <c:forEach items="${videos }" var="video">
												    <tr style="cursor:pointer;vertical-align: middle;" onclick="setVideoMsg(this)" class="column" data-toggle="modal" data-target="#myModal">
												      <td>${video.id }</td>
												      <td><img src="${pageContext.request.contextPath}/${video.thumbnailUrl}" class="img-circle media-image-m center-block"></td>
												      <td>${video.name }</td>
												      <td>${video.user.nickname }</td>
												      <td><fmt:formatDate value="${video.uploadTime }" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
												      <td><fmt:formatDate value="${video.duration }" pattern="HH:mm:ss"/> </td>
												      <td>
													      <c:choose>
													      	<c:when test="${video.videoState.id == 4 }">等待审核</c:when>
													      	<c:when test="${video.videoState.id == 5 }">审核通过</c:when>
													      	<c:otherwise>审核不通过</c:otherwise>
													      </c:choose> 
												      </td>
												    </tr>
											      </c:forEach>
											  </tbody>
											</table>
										</div>
									</div>
							</form>
						</div>
						<div class="account-email-bind user-item " style="display: none;">
							<div class="account-message-header">
								<h3>留言管理</h3>
								<hr />
							</div>
						<div class="account-email-content">
							<form class="form-horizontal" role="form">
								<div class="form-group clearfix" style="vertical-align: middle;">
								   <label class="col-sm-2 control-label" style="display:block;">请选择审核类型：</label>
								   <div class="col-sm-6">
								     <select class="form-control msg_verify" onchange="changeMsg(this)">
								     	<option value="comment" selected="selected">审核留言</option>
								     	<option value="reply">审核回复</option>
								     </select>
								   </div>
								 </div>
							</form>
							<div class="column clearfix" style="padding-top:20px">
								<table class="table table-hover">
									  <thead>
									    <tr>
									      <th>编号</th>
									      <th>发表用户</th>
									      <th>发表内容</th>
									      <th>发表时间</th>
									      <th>状态</th>
									    </tr>
									  </thead>
									  <tbody class="comm_detail">
										  <c:forEach items="${comments }" var="comment">
										    <tr style="vertical-align: middle;" class="column">
										      <td>${comment.id }</td>
										      <td>${comment.user.nickname }</td>
										      <td>${comment.detail }</td>
										      <td><fmt:formatDate value="${comment.commTime }" pattern="yyyy-MM-dd HH:mm:ss"/> </td>
										      <td><a class="confirm_verify" onclick="confirm_verify(this)">等待审核</a></td>
										    </tr>
									      </c:forEach>
									  </tbody>
									</table>
								</div>
							</div>
						</div>

					</div>
				</div>
			</div>
			<!-- End 报表编辑页面内容   -->
		</div>
		<!-- //container -->
	</div>
	<!-- //upload -->
	
	<jsp:include page="footer.jsp"></jsp:include>
	</div>
	
	<!-- 视频审核 -->
	<div class="video-list-toadd"> 
		<!-- 模态框（Modal） -->
		<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;
				</button>
						<h4 class="modal-title" id="myModalLabel">
					视频审核
				</h4> 
					</div>
					<div class="modal-body">
					<form action="${pageContext.request.contextPath}/admin/save" method="post" class="save_form">
						<input class="video_id" type="hidden" name="videoId"/>
						<table class="my-modal-table table table-bordered">
								<tr>
									<td class="text-right">视频名称：</td>
									<td class=""><input type="text" readonly="readonly" value="" class="form-control video_name"/></td>
								</tr>
								<tr>
									<td class="text-right">分类：</td>
									<td class=""><input type="text" readonly="readonly" name="" id="" value="" class="form-control video_category"/></td>
								</tr>
								<tr>
									<td class=" text-right">简介：</td>
									<td class=""><textarea type="text" readonly="readonly" name="" id="" value="" class="form-control video_intro"></textarea></td>
								</tr>
								<tr>
									<td class=" text-right">视频：</td>
									<td><span href="${pageContext.request.contextPath }/video/13.flv" style="display:block" id="player" class="play_video_z">  
										</span></td> 
								</tr>
								<tr>
									<td class="text-right">改变状态：</td>
									<td class="">
										<select class="form-control video_state" name="videoStateId">
											<option value="4">等待审核</option>  
											<option value="5">审核通过</option>  
											<option value="6">审核不通过</option>
										</select>
									</td>
								</tr>    
							</table>
						</form>
					</div>
					<div class="modal-footer clearfix">
							<button type="button" class="btn btn-info" onclick="save_video_state()">保存</button>
							<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
						</div>
				</div>
				<!-- /.modal-content -->
			</div>
			<!-- /.modal-dialog -->
		</div>
	</div>

	<script src="${pageContext.request.contextPath}/js/bootstrap.min.js"></script>
	<script type="text/javascript">
			$(document).ready(function () {  
				active_play();
		    }); 
			function active_play() {
				flowplayer("player", "${pageContext.request.contextPath}/videoplayer/flowplayer-3.2.8.swf", {
					clip: { 
		　　　　　　　　　 autoPlay: false,//自动播放    
		          		 autoBuffering:true //是否开启缓冲
			          }});
			};
		$(function() {
			$('.report-left-cell').eq(0).css('color', 'white').css(
					'background-color', '#92bbfe');
			$('.report-left-cell').click(
				function() {
					$('.report-left-cell').each(
							function() {
								$(this).css('color', 'black').css(
										'background-color', 'white');
							});
					$('.user-item').each(function() {
						$(this).css('display', 'none');
					});
					$('.user-item').eq($(this).index()).css('display',
							'block');
					$(this).css('color', 'white').css('background-color',
							'#92bbfe');
				});
		});
	    function setVideoMsg(e) {
			$.ajax({
	            url:"${pageContext.request.contextPath}/admin/each_video",
	            type:"post",  //提交方式，post或get
		 		    async:true, 	//同步或者异步方式，true表示异步，异步方式不会阻塞当前网页,但是会造成处理已经完成但是请求还没完成
	            	datatype:'json',
		 			data:{id: $(e).children(":first").html()},  //提交的请求参数，是键值对，用：隔开
		 			success:function(redata){ //请求成功的回调函数，参数是响应的返回值
						$(".video_name").attr("value", redata.name);
						$(".video_intro").html(redata.intro);
						$(".video_category").attr("value", redata.categoryName);
						$("#player").attr("href", '${pageContext.request.contextPath}/'+redata.url);
						$(".video_id").attr("value", redata.id);
						$('.video_state option').each(function() {
							$(this).attr('selected', false);
							if($(this).val() == redata.state) {
								$(this).attr('selected', true);
							}
						});
						active_play();
		 			}
	        });
		}; 
		function save_video_state() {
			$(".save_form").submit();			
		}
	/* 	
		$('.comm_detail .confirm_verify').on('click', function(){
			layer.confirm('确定封禁此条信息吗？', {
				  btn: ['确认','取消'] //按钮
				}, function(){
				  layer.msg('封禁成功', {icon: 1});
				  layer.alert($(this).size());
				});
		}); */
		
		function confirm_verify(e) {
			layer.confirm('如何处理此条信息吗？', {
				  btn: ['没有问题','封禁信息', '取消'] //按钮
				}, function(){
				  layer.msg('还原成功', {icon: 1});
				  var id = $(e).parent().parent().children(":first").html();
				  var type = $('.msg_verify option:selected').val();
				  updateCommReplyState(id, type, 0);
				}, function(){
				  layer.msg('封禁成功', {icon: 1});
				  var id = $(e).parent().parent().children(":first").html();
				  var type = $('.msg_verify option:selected').val();
				  updateCommReplyState(id, type, 2);
				});
		};
		
		function updateCommReplyState(id, type, state) {
			$.ajax({
	            url:"${pageContext.request.contextPath}/comment/update_state",
	            type:"post",  //提交方式，post或get
	 		    async:true, 	//同步或者异步方式，true表示异步，异步方式不会阻塞当前网页,但是会造成处理已经完成但是请求还没完成
            	datatype:'json',
	 			data:{id:id, type:type, state:state},  //提交的请求参数，是键值对，用：隔开
	 			success:function(redata){ //请求成功的回调函数，参数是响应的返回值
	               var $comm_detail = $(".comm_detail");
	               $comm_detail.html("");
				   for(var i=0; i < redata.length; i++){
					  $comm_detail.append("<tr style='vertical-align: middle;' class='column'><td>"
					  + redata[i].id + "</td><td>" + redata[i].user.nickname + "</td><td>" + redata[i].detail
				      + "</td><td>" + redata[i].formatTime + "</td><td><a class='confirm_verify' onclick='confirm_verify(this)'>等待审核</a></td>");
				   } 			
	            }
	        });
		};
		
		function changeMsg(e) {
			var type = $(e).children("option:selected").val();
			$.ajax({
	            url:"${pageContext.request.contextPath}/comment/chang_msg",
	            type:"post",  //提交方式，post或get
	 		    async:true, 	//同步或者异步方式，true表示异步，异步方式不会阻塞当前网页,但是会造成处理已经完成但是请求还没完成
            	datatype:'json',
	 			data:{type:type},  //提交的请求参数，是键值对，用：隔开
	 			success:function(redata){ //请求成功的回调函数，参数是响应的返回值
	                var $comm_detail = $(".comm_detail");
	                $comm_detail.html("");
				   for(var i=0; i < redata.length; i++){
					  $comm_detail.append("<tr style='vertical-align: middle;' class='column'><td>"
					  + redata[i].id + "</td><td>" + redata[i].user.nickname + "</td><td>" + redata[i].detail
				      + "</td><td>" + redata[i].formatTime + "</td><td><a class='confirm_verify' onclick='confirm_verify(this)'>等待审核</a></td>");
				   } 			
	            }
	        });
		}


	</script>
</body>
</html>